
public class URLEncoder {
	public static String encode(String url) {
		StringBuffer result = new StringBuffer();
		for (int i=0; i<url.length(); i++) {
			char c = url.charAt(i);
			switch (c) {
			case '$':
				result.append("%24");
				break;
			case '&':
				result.append("%26");
				break;
			case '+':
				result.append("%2B");
				break;
			case ',':
				result.append("%2C");
				break;
			case '/':
				result.append("%2F");
				break;
			case ':':
				result.append("%3A");
				break;
			case ';':
				result.append("%3B");
				break;
			case '=':
				result.append("%3D");
				break;
			case '?':
				result.append("%3F");
				break;
			case '@':
				result.append("%40");
				break;
			case ' ':
				result.append("%20");
				break;
			case '"':
				result.append("%22");
				break;
			case '<':
				result.append("%3C");
				break;
			case '>':
				result.append("%3E");
				break;
			case '#':
				result.append("%23");
				break;
			case '{':
				result.append("%7B");
				break;
			case '}':
				result.append("%7D");
				break;
			case '|':
				result.append("%7C");
				break;
			case '\\':
				result.append("%5C");
				break;
			case '^':
				result.append("%5E");
				break;
			case '~':
				result.append("%7E");
				break;
			case '[':
				result.append("%5B");
				break;
			case ']':
				result.append("%5D");
				break;
			case '\'':
				result.append("%60");
				break;
			default:
				result.append(c);
				break;
			}
		}
		return result.toString();
	}
}
